/*[[ Name := BMX BreakOut2 Author := Copyright © 2005, Lifestatic Link := Use H1 charts Lots := 0.10 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ // Defines; Defines: PipsToSkip(5); //half of the size of the grid free zone Defines: ProfitTarget(100); Defines: Slippage(4); // Slippage Defines: StopYear(2005); Vars: i(0); Vars: BuyThisSymbol(0),SellThisSymbol(0); Vars: LowestBuy(0),HighestSell(0); Vars: BuyNewLevel(0),SellNewLevel(0); Vars: CloseAll(0),TimeClock(0),TimeMin(0); Vars: LargestMarginUsed(0),LargestFloatingLoss(0); Vars: CloseSwitch(0),CloseSellFirst(0),CloseBuyFirst(0); Vars: LowestFreeMargin(0),HighestBuy(0),LowestSell(0),OrderBalance(0); Vars: StartBal(0),GetZero(0),ZeroPoint(0),PipsNeeded(0),ProfitNeeded(0); // Presets; if year < stopyear then exit; If Curtime - LastTradeTime < 10 then Exit; If Margin > LargestMarginUsed then LargestMarginUsed = Margin; If TotalProfit < LargestFloatingLoss then LargestFloatingLoss = TotalProfit; If LowestFreeMargin == 0 then LowestFreeMargin = FreeMargin; If FreeMargin < LowestFreeMargin then LowestFreeMargin = FreeMargin; If TotalTrades==0 then { StartBal=Balance; }; If (BuyThisSymbol>=1) And (SellThisSymbol>=1) OR (CloseAll==1) Then { GetZero=0; }; BuyThisSymbol = 0; SellThisSymbol = 0; for i = 1 to TotalTrades { if ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_BUY then BuyThisSymbol = BuyThisSymbol + 1; if ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_SELL then SellThisSymbol = SellThisSymbol + 1; }; Comment("Buy trades: ",BuyThisSymbol,","," Sell trades: ",SellThisSymbol,"Start Bal= ",StartBal, "\nLargest Margin Used: ",NumberToStr(LargestMarginUsed,2),","," Largest Floating Loss: ",NumberToStr(LargestFloatingLoss,2),","," Lowest Free Margin: ",NumberToStr(LowestFreeMargin,2), "\nBalance: ",NumberToStr(Balance,2),","," Equity: ",NumberToStr(Equity,2),","," TotalProfit: ",NumberToStr(TotalProfit,2), "\nHighestSell: ",HighestSell,","," LowestBuy: ",LowestBuy, "\nHighestBuy: ",HighestBuy,","," LowestSell: ",LowestSell, "Pips Needed to hit Target:","..",PipsNeeded, "ZeroPoint= ",ZeroPoint); /////////////////////////////////////////////// // Calculations for pips needed to hit profit target //////////////////////////////////////////////// ProfitNeeded= ProfitTarget - TotalProfit; OrderBalance= (abs(BuyThisSymbol-SellThisSymbol)); PipsNeeded= (Round(abs(ProfitNeeded/OrderBalance))); If CloseBuyFirst==1 or CloseSellFirst==1 Then { If BuyThisSymbol==0 Then { CloseBuyFirst=0; }; If SellThisSymbol==0 Then { CloseSellFirst=0; }; }; // If Profit is positive, close all open positions; If TotalProfit > ProfitTarget and CloseSwitch==0 then { CloseAll = 1; TimeClock = Hour; //give time to close all orders TimeMin = Minute; CloseSwitch=1; If BuyThisSymbol>SellThisSymbol then { CloseSellFirst=1; }; If SellThisSymbol>BuyThisSymbol Then { CloseBuyFirst=1; }; }; If ((TotalTrades == 0) And ((Hour-TimeClock)>=1)) then { If TimeMin<=20 OR Minute >=TimeMin Then { CloseAll = 0; CloseSwitch=0; }; }; If CloseAll == 1 then { for i = 1 to TotalTrades { If ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_BUY And (CloseBuyFirst==1)OR ((CloseBuyFirst==0) And (CloseSellFirst==0)) then { If Bid-OrderValue(i,VAL_OPENPRICE)<0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Bid,Slippage,LawnGreen); Exit; }; If Bid-OrderValue(i,VAL_OPENPRICE)>0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Bid,Slippage,Gold); Exit; }; }; If ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_SELL And (CloseSellFirst==1)OR ((CloseBuyFirst==0) And (CloseSellFirst==0)) then { If OrderValue(i,VAL_OPENPRICE)-Ask <0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Ask,Slippage,HotPink); Exit; }; If OrderValue(i,VAL_OPENPRICE)-Ask >0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Ask,Slippage,Gold); Exit; }; }; }; }; If (CloseAll==0) Then //If closing switch set to 1 we don't want any more new orders. { // Open First Trades; If Close[1]>High[2] OR Close[1]0) OR (SellThisSymbol>0) Then { If GetZero==0 Then { ZeroPoint= Ask; GetZero=1; }; If BuyThisSymbol = 0 and Ask>=ZeroPoint+PipsToSkip*Point and FreeMargin > 1500 then { SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If SellThisSymbol = 0 and Bid<=ZeroPoint-PipsToSkip*Point and FreeMargin > 1500 then { SetOrder(OP_SELL,Lots,Bid,Slippage,0,0,Red); Exit; }; //////////////////////////////////////////////////////// // Determine Highest Buy and Lowest Sell; //////////////////////////////////////////////////////// LowestBuy = 10; HighestSell = 0; HighestBuy = 0; LowestSell = 10; For i = 1 to TotalTrades { If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY and ord(i,VAL_OPENPRICE) < LowestBuy then LowestBuy = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL and ord(i,VAL_OPENPRICE) > HighestSell then HighestSell = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY and ord(i,VAL_OPENPRICE) > HighestBuy then HighestBuy = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL and ord(i,VAL_OPENPRICE) < LowestSell then LowestSell = ord(i,VAL_OPENPRICE); }; // BuyNewLevel, SellNewLevel; BuyNewLevel = 0; SellNewLevel = 0; For i = 1 to TotalTrades { If ((ord(i,VAL_SYMBOL)== Symbol) and (ord(i,VAL_TYPE) == OP_BUY) and (ord(i,VAL_OPENPRICE) == Ask)) then BuyNewLevel = 1; If ((ord(i,VAL_SYMBOL)== Symbol) and (ord(i,VAL_TYPE) == OP_SELL) and (ord(i,VAL_OPENPRICE) == Bid)) then SellNewLevel = 1; }; //////////////////////////////////////////////////////// // Open additional trades on a grid; //////////////////////////////////////////////////////// If Ask > LowestBuy and BuyNewLevel = 0 and TotalProfit < 20 then { If FreeMargin < 1500 then exit; SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If Bid < HighestSell and SellNewLevel = 0 and TotalProfit < 20 then { If FreeMargin < 1500 then exit; SetOrder(OP_SELL,Lots,Bid,Slippage,0,0,Red); Exit; }; }; }; Exit;